package com.netease.nie.filters;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.netease.nie.base.cache.redis.Redis;

/**
 * 
 * @author KingsHunter
 * @createDate June 25th,2016
 *
 */
@WebFilter(filterName = "userFilter", value = {"/api/my_privilege/goods_list", "/api/column_goods"})
public class UserFilter implements Filter {

	@Autowired
	private Redis redis;
	
	public void destroy() {
		System.out.println("aaaa");
	}

	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
			FilterChain filterChain) throws IOException, ServletException {
		System.out.println("执行过滤操作");
		String userToken = servletRequest.getParameter("userToken");
		if (StringUtils.isNotBlank(userToken)) {
			//根据用户token信息查询用户信息
			String a = redis.get(userToken);
			//
			servletRequest.setAttribute("userInfo", 1);
		}
		
		filterChain.doFilter(servletRequest, servletResponse);
	}

	public void init(FilterConfig filterChain) throws ServletException {
		System.out.println("bbbbbbbbbbbbbbb");

	}

}
